package provider
{
	import com.google.maps.Alpha;
	import com.google.maps.CopyrightCollection;
	import com.google.maps.TileLayerBase;
	import com.google.maps.interfaces.ICopyrightCollection;
	
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.geom.Point;
	import flash.net.URLRequest;
	
	public class OpenstreetProvider extends TileLayerBase
	{
		public function OpenstreetProvider(minResolution:Number = 0,
                                            maxResolution:Number = 17,
                                            alpha:Number=Alpha.OPAQUE)
		{
		
			 var copyright:ICopyrightCollection = new CopyrightCollection("<a href=\"http://www.openstreetmap.org/\">OpenStreetMap</a>");
            super(copyright,minResolution,maxResolution,alpha);        
		}
		
		
		public override function loadTile(tilePos:Point, zoom:Number):DisplayObject {            
            
//            var tilesMapnik     = new GTileLayer(copyOSM, 1, 17, {tileUrlTemplate: 'http://tile.openstreetmap.org/{Z}/{X}/{Y}.png'});
//    		var tilesOsmarender = new GTileLayer(copyOSM, 1, 17, {tileUrlTemplate: 'http://tah.openstreetmap.org/Tiles/tile/{Z}/{X}/{Y}.png'});
// 
//    		var mapMapnik     = new GMapType([tilesMapnik],     G_NORMAL_MAP.getProjection(), "Mapnik");
//    		var mapOsmarender = new GMapType([tilesOsmarender], G_NORMAL_MAP.getProjection(), "Osmarend");

//			var dd:Point
			
			var tilesMapnik:String = "http://tile.openstreetmap.org/{Z}/{X}/{Y}.png";
			tilesMapnik = tilesMapnik.replace("{Z}",zoom.toString());
			tilesMapnik = tilesMapnik.replace("{X}",tilePos.x.toString());
			tilesMapnik = tilesMapnik.replace("{Y}",tilePos.y.toString());
			
			var tilesOsmarender:String = "http://tah.openstreetmap.org/Tiles/tile/{Z}/{X}/{Y}.png";
			tilesOsmarender = tilesOsmarender.replace("{Z}",zoom.toString());
			tilesOsmarender = tilesOsmarender.replace("{X}",tilePos.x.toString());
			tilesOsmarender = tilesOsmarender.replace("{Y}",tilePos.y.toString());
            var loader:Loader = new Loader();
            
            
            
            var tileUrl:String = tilesMapnik;
            trace("OpenstreetProvider.as line 47 : " + tilesMapnik)
            loader.load(new URLRequest(tileUrl));
            return loader;
        } 
	}
}